//
//  JSMDreamCityPrefectureDetailsViewController.m
//  TakeYouTourTogether
//
//  Created by king on 15/12/3.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMDreamCityPrefectureDetailsViewController.h"
#import "JSMDreamCityPrefectureDetailTableViewCell.h"
#import "JSMDreamCityPrecialTrailsModel.h"
#import "JSMDreamCityPrecialTrailsDetailModel.h"
#import "JSMDreamCityPrefectureTrailsDetailsViewController.h"

@interface JSMDreamCityPrefectureDetailsViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong) BaseTableView *myTableView;
@property(nonatomic, strong) NSArray *tempArray;

@end

@implementation JSMDreamCityPrefectureDetailsViewController

#pragma mark - Method viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithWhite:0.882 alpha:1.000]	;
    self.myTableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    self.myTableView.bounces = NO;
    self.myTableView.separatorStyle = NO;
    [self.view addSubview:self.myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self requestDataFromNetWorking];
}
#pragma mark - Method 每个分区返回一行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tempArray.count;
}
#pragma mark - Method 专区cell样式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *resue = @"dreamCityPrefectureDetailTableViewResue";
    JSMDreamCityPrefectureDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resue];
    if (!cell) {
        cell = [[JSMDreamCityPrefectureDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resue];
    }
    JSMDreamCityPrecialTrailsDetailModel *temp = self.tempArray[indexPath.row];
    cell.tempModel = temp;
    return cell;
}
#pragma mark - Method 每个cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    JSMDreamCityPrecialTrailsDetailModel *temp = self.tempArray[indexPath.row];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
    CGRect rect = [temp.mydescription boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return 250*ALL_EDITION_HEIGHT + rect.size.height+10;
}
#pragma mark - Method requestDataFromNetWorking 网络请求数据
- (void)requestDataFromNetWorking {
    NSString *strURL = [NSString stringWithFormat:@"http://tubu.ibuzhai.com/rest/v1/trail/type/%@?&app_version=4.3.3&page_size=20&api_version=1&page=1&device_type=2&access_token=&type_id=%@", self.tempModel.vid, self.tempModel.vid];
    [AFNetworkingTool getUrl:strURL hudSuperView:self.view result:JSON success:^(id result) {
        NSDictionary *dic = result;
        //        NSLog(@"%@", dic);
        JSMDreamCityPrecialTrailsModel *dreamCityPrecialTrailsModel = [[JSMDreamCityPrecialTrailsModel alloc] init];
        [dreamCityPrecialTrailsModel setValuesForKeysWithDictionary:dic];
        self.tempArray = dreamCityPrecialTrailsModel.trailsArray;
        // 懒加载 分享按钮
        //        [self.shareButton setTintColor:[UIColor whiteColor]];
        // tableView 刷新
        [self.myTableView reloadData];

        
    } failure:^(NSError *error) {
        
        
    }];
}
#pragma mark - Method 点击跳转旅游地详情
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    JSMDreamCityPrefectureTrailsDetailsViewController *controller = [[JSMDreamCityPrefectureTrailsDetailsViewController alloc] init];
    controller.tempModel = self.tempArray[indexPath.row];
    [self.navigationController pushViewController:controller animated:YES];
}
#pragma mark - Method didReceiveMemoryWarning
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
